package com.fpno.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
/*@RequestMapping("/hello")*/
public class RequestMappingController {

    /*@RequestMapping("/testRequestMapping")*/
    @RequestMapping(
            value = {"testRequestMapping","test"}, /*必须设置*/
            method = {RequestMethod.POST,RequestMethod.GET}  /*如果不设置则默认为接受任何种类的请求*/

    )
    public String success(){
        return "success";
    }

    @GetMapping("/testGetMapping")
    public String testGetMapping(){
        return "success";
    }

    @RequestMapping(value = {"/testput"},method = {RequestMethod.PUT})
    public String testput(){
        return "success";
    }

    @RequestMapping(
            value = {"/testParamsAndHeaders"},
            params = {"username","password!=123456"}, /*params需要同时匹配*/
            headers = {"Host=localhost:8080"}
            )
    public String testParamsAndHeaders(){
        return "success";
    }

    //@RequestMapping("/a?a/testAnt")/* ? 表示任意的单个字符*/
    //@RequestMapping("/a*a/testAnt")/* * 表示0或多个字符 */
    @RequestMapping("/**/testAnt")// **表示任意的一层或多层目录 在使用**时，只能使用/**/xxx的方式
    public String testAnt(){
        return "success";
    }

    @RequestMapping("/testPath/{id}")
    public String testPath(@PathVariable("id")Integer id){// @PathVariable("id")将占位符中的id赋值给形参id
        System.out.println("id:"+id);
        return "success";
    }

}
